﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        /*JS编程练习1
        随机产生50个整数，统计多少个正数，多少个负数，多个个0
        */

        var t = GetRandomArray(-50, 50, 50);
        var z = 0;//+
        var f = 0; //-
        var zero = 0;//0
        for (var i = 0; i < t.length; i++) {
            if (t[i] < 0) f++;
            else if (t[i] > 0) z++;
            else zero++;
        }
        document.write("正数个数:" + z + "<br/>负数个数:" + f + "<br/>0的个数：" + zero);
        function GetRandomArray(min, max, length) {
            var temp = new Array(); //创建一个数组           
            for (var i = 0; i < length; i++) {
                temp[i] = GetRandomIntNumber(min, max);                
            }
            return temp;
        }
        function GetRandomIntNumber(min, max) {
            var cur = Math.random();
            var t = (1 - cur) / cur;
            return Math.round((max + t * min) / (1 + t));
        }
    </script>
</head>
<body>
</body>
</html>
